<?php

namespace app\client\model;

use think\Model;
use think\Request;
use app\console\model\MemberMessage as MemberMessageModel;

class Coupon extends Model
{

    // 模型事件
    protected static function init()
    {
        // 写入前
        self::event('before_write', function ($data) {
            $interval_timer = explode(' / ', Request::instance()->param('interval_timer'));
            $data->start_time = strtotime($interval_timer[0]);
            $data->end_time = strtotime($interval_timer[1]);
            $data->parenTid = 0;
            $data->sort = 0;
        });

        // 新增后
        // self::event('after_insert', function ($data) {
        //     $model = new MemberMessageModel();
        //     $model->save(['member_id' => '0', 'title' => $data->title, 'content' => $data->content, 'create_time' => date('Y-m-d H:i:s', time())]);
        // });
    }

}
